using UnityEngine;

namespace Brick
{
	public class FPSCounter : MonoBehaviour
	{
		private float updateInterval = 1f;

		private float accum;

		private float frames;

		private float timeleft;

		private float fps = 15f;

		private float lastSample;

		private float gotIntervals;

		private void Start()
		{
			timeleft = updateInterval;
			lastSample = Time.realtimeSinceStartup;
		}

		private void Update()
		{
			frames += 1f;
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			float num = realtimeSinceStartup - lastSample;
			lastSample = realtimeSinceStartup;
			timeleft -= num;
			accum += 1f / num;
			if (timeleft <= 0f)
			{
				fps = accum / frames;
				timeleft = updateInterval;
				accum = 0f;
				frames = 0f;
				gotIntervals += 1f;
			}
		}

		private void OnGUI()
		{
			GUI.Label(new Rect(0f, 50f, 200f, 200f), "FPS:" + fps.ToString("f2"));
		}
	}
}

